package top.lbqaq.service;

import top.lbqaq.dao.BaseDao;
import top.lbqaq.dao.ProductDao;
import top.lbqaq.dao.ProductInDao;
import top.lbqaq.pojo.Product;
import top.lbqaq.pojo.ProductIn;
import top.lbqaq.util.pageBean;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Gor
 */
public class ProductInService {
    private final ProductInDao productInDao = new ProductInDao();
    public pageBean<ProductIn> selectAllProductIn(int pageNum, int pagesize){
        Connection connection = BaseDao.getConnection();
        try {
            List<ProductIn> allProducts = productInDao.getAllProductIn(connection);
            int totalRecord =allProducts.size();
            pageBean pb=new pageBean(pageNum,pagesize,totalRecord);
            int startIndex=pb.getStartIndex();
            pb.setList(productInDao.getAllProductInpg(startIndex,pagesize,connection));
            return pb;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;

    }
    public int updateInById(int number,int id) {
        Connection connection = BaseDao.getConnection();
        int n=0;
        try {

            // List<Product> allProducts = productDao.updateAllById(connection,product);
            n=productInDao.updateInById(connection,id,number);

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return n;
    }
    public int insertproductIn(ProductIn product) {
        Connection connection = BaseDao.getConnection();
        int n=0;
        try {

            // List<Product> allProducts = productDao.updateAllById(connection,product);
            n=productInDao.insert(connection,product);

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return n;
    }
}
